package cn.signalpha.modules.system.controller;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.modules.system.entity.OperateLog;
import cn.signalpha.modules.system.service.IOperateLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/admin/operate/log")
@Api(value = "操作日志", tags = "操作日志")
public class OperateLogController extends BaseController {

	private final IOperateLogService IOperateLogService;

    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<OperateLog>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
        QueryWrapper<OperateLog> queryWrapper = Condition.getQueryWrapper(params, OperateLog.class);
        return R.data(IOperateLogService.page(Condition.getPage(query), queryWrapper.lambda().orderByDesc(OperateLog::getId)));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<OperateLog> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(IOperateLogService.getById(id));
	}

}
